package com.bangyo.common.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.filter.GenericFilterBean;

/**
 * 抽象的HTTP过滤器。
 * 
 * @author Topbit 2006-5-24 14:34:40
 */
public abstract class AbstractHttpFilter extends GenericFilterBean
{
    public AbstractHttpFilter()
    {
        super();
    }

    protected final Log logger = LogFactory.getLog(getClass());

    public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("filter["+this.getFilterName()
                +"] start, begin doHttpFilter.");
        }

        doHttpFilter((HttpServletRequest)request,
            (HttpServletResponse)response, chain);

        if (logger.isDebugEnabled())
        {
            logger.debug("filter["+this.getFilterName()+"] end.");
        }
    }

    protected abstract void doHttpFilter(HttpServletRequest request,
        HttpServletResponse response, FilterChain chain) throws IOException,
        ServletException;
}